package com.google.code.gronono.gps.ui.controller.actions;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.net.URL;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;

import com.google.code.gronono.commons.i18n.BundleKey;
import com.google.code.gronono.commons.i18n.BundleName;
import com.google.code.gronono.gps.ui.controller.GPSController;

/**
 * Action permettant de déclencher le traitement.
 *
 * @author Arnaud BRUNET
 *
 * @see GPSController#sort()
 */
@BundleName(value = "com.google.code.gronono.gps.gui")
public class SortAction extends AbstractAction {
	/** serialVersionUID */
	private static final long serialVersionUID = 9154995971871413412L;

	/** Nom de l'action. */
	@BundleKey(value = "action.sort.name")
	private static String ACTION_NAME;
	/** Icône de l'action. */
	@BundleKey(value = "action.sort.icon")
	private static String ICON;

	/** Le contrôleur. */
	private final GPSController controller;

	/**
	 * Construit l'action à partir du contrôleur.
	 * @param controller Le contrôleur.
	 */
	public SortAction(final GPSController controller) {
		super(ACTION_NAME);
		final URL url = this.getClass().getClassLoader().getResource(ICON);
		this.putValue(SMALL_ICON, new ImageIcon(url));
		this.putValue(MNEMONIC_KEY, KeyEvent.VK_T);
		this.controller = controller;
	}

	/*
	 * (non-Javadoc)
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
	public void actionPerformed(final ActionEvent e) {
		this.controller.sort();
	}

}
